<%@page import="itsm.isperp.module.entity.callcenter.CcAgent"%>
<%@page import="itsm.isperp.framework.web.request.JqGridFilterRuleOp"%>
<%@page import="itsm.isperp.framework.web.request.JqGridRequest"%>
<%@page import="itsm.isperp.module.service.callcenter.CcAgentService"%>
<%@page import="itsm.isperp.framework.core.context.ContextHolder"%>
<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:include page="includes/top.jsp"></jsp:include>


<script type="text/javascript" src="wro/main.js"></script>



<script type="text/javascript">
	$(document).ready(function() {
		$("#rootTopMenus li:first").click();
	});

	function switchMenu(obj) {
		var $this = $(obj), t = $this.data("t");

		if (t == "1") {
			$this.data("t", "2");
			$("#dvFrameMainNav").css("width", "28px");
			$("#mainContent").css("left", "28px");
			$this.css("background-position", "-22px -31px");
			$(".skin-left").css("width", "26px");
			$("#navtree").hide();
			$("#mainContent").css("top", "0");
		} else {
			$this.data("t", "1");
			$("#dvFrameMainNav").css("width", "200px");
			$("#mainContent").css("left", "210px");
			$("#mainContent").css("top", "10px");
			$this.css("background-position", "-22px -15px");
			$("#navtree").show("normal");
			$(".skin-left").css("width", "200px");
		}

	}

	function menuOnclick(obj) {
		$(".collapsible .current").removeClass("current");
		var parent = $(obj).parent();
		isperp.showInWorkspace(obj);
		parent.addClass("current");
		parent.parent().parent().addClass("current");
		return false;
	}

	function loadModuleMenus(moduleId, obj) {

		$("#rootTopMenus li").removeClass("active");
		$(obj).addClass("active");

		if (moduleId == "") {

			$("#dvFrameMainNav").hide();
			$("#skin .skin-left").hide();
			$("#mainContent").css("left", "0px");

			$("#dvContainer").html("<iframe src='app/portal/indexView'  style='width:100%;height:100%' scrolling='auto' frameborder='0'></iframe>");
			return;
		}

		$("#skin .skin-left").show();
		$("#dvFrameMainNav").show();
		$("#mainContent").css("left", "210px");

		var $menu = $('#navtree').children('ul');

		//$menu.html("载入中..."); 

		$.getJSON("app/menu/getModuleMenu", {
			"moduleId" : moduleId
		}, function(result) {
			if (result == null || result == "") {
				return;
			}
			result = result[0].children;
			var menus = "";

			$(result).each(function(index, item) {

				if (index == 0) {
					menus += "<li class='secondli open'>";
					menus += " <a href='javascript:void(0);'><span class='fn-bg nui-ico-dArr'></span>" + item.name + "</a>";
					menus += "<ul id='rootTopMenusList' class='sub' style=''>";
				} else {
					menus += "<li class='secondli'>";
					menus += "<a href='javascript:void(0);'><span class='fn-bg nui-ico-dArr'></span>" + item.name + "</a>";
					menus += "<ul class='sub' style='display: none;'>";
				}
				$(item.children).each(function(cIndex, cItem) {
					var customerId = '${customer_id}';
					var deptTreePath = '${department_treenode_path}';
					var curUserName = '${curUserName}';
					var turl = cItem.url;
					if (curUserName != 'admin')
						turl = cItem.url.replace("{customerId}", customerId).replace("{deptTreeNodePath}", deptTreePath);
					else
						turl = cItem.url.replace("{customerId}", "").replace("{deptTreeNodePath}", "");
					if (cItem.openType == "newWindow") {
						menus += "<li class='with-icon'><a openType='" + cItem.openType + "' href='" + turl + "' navpath='" + cItem.treenodeNamePath + "' target='_black'><span class='icon icon-cog'></span>" + cItem.name;
					} else {
						menus += "<li class='with-icon'><a openType='" + cItem.openType + "' href='" + turl + "' navpath='" + cItem.treenodeNamePath + "' onclick='javascript:return menuOnclick(this);' ><span class='icon icon-cog'></span>" + cItem.name;
					}
					if (cItem.countUrl && cItem.countUrl != "") {
						menus += "<span class='msg_count'  data-counturl='"+cItem.countUrl+"'></span>";
					}

					menus += "</a></li>";
				});

				menus += "</ul><li>";

			});

			$menu.html(menus);
			initMenu($menu);
			setMenuMsgCount();
			$("#rootTopMenusList a:first").click();

		});
	}

	function setMenuMsgCount() {
		$("#navtree .msg_count").each(function(index, item) {
			var $item = $(item);
			var counturl = $item.data("counturl");
			//避免缓存
			$.ajax({
				url : counturl,
				cache : false,
				type : "get",
				success : function(data) {
					$item.text("(" + data + ")");
				}

			});

		});
	}

	window.setInterval(setMenuMsgCount, 60000);
</script>

<c:choose>
	<c:when test="${empty noHeader }">
		<jsp:include page="includes/toptoolbar.jsp"></jsp:include>
		<header id="rootHeader" class="container_12">
			<h1 class="pP ou" id="h1Logo">
				<a href="javascript:void(0);" class="ow"><img
					src="<%=ContextHolder.getConfigByKey("companyLogo")%>"
					alt="<%=ContextHolder.getConfigByKey("companyIntro")%>" border="0"
					id="imgLogo"> </a>
			</h1>
			<h3 class="pP ou" id="h3Logo"
				style="left:<%=ContextHolder.getConfigByKey("companyIntroLeft")%>px"><%=ContextHolder.getConfigByKey("companyIntro")%></h3>
			<div class="qq" id="dvTab">

				<ul id="rootTopMenus" class="qd nui-tabs">
					<li id="indexli" href="javascript:void(0)"
						onclick="loadModuleMenus('',this)" class="qa nui-tabs-item""><span
						class="nui-tabs-item-text">首页</span>
					</li>
					<c:forEach items="${root}" var="menu">
						<li href="javascript:void(0)"
							onclick="loadModuleMenus('${menu.id}',this)"
							class="qa nui-tabs-item"><span class="nui-tabs-item-text">${menu.name}
						</span>
						</li>
					</c:forEach>
				</ul>
				<div class="pv"></div>
			</div>
		</header>
		<section class="frame-main" style="top: 88px;">

			<div id="dvFrameMainNav" class="frame-main-nav">
				<div onclick="switchMenu(this)" data-t="1" id="switchMenuBtn"
					style="position: absolute;right: .5em;top: 1em;margin-top: -8px;background: url(img/icon_jd.png) no-repeat -22px -15px;cursor: pointer;width: 16px;height: 16px;padding: 0;"></div>
				<aside aria-labeledby="dvNavTitle" role="navigation">
					<div class="pj nui-scroll" id="navtree">
						<ul class="collapsible accordion nui-tree" role="tree"></ul>
					</div>
				</aside>
			</div>
			<section id="mainContent"
				class="frame-main-cont frame-main-cont-first" role="main">
				<div id="dvContainer" style="overflow:visible;"></div>
			</section>
		</section>
	</c:when>
	<c:otherwise>

		<header id="rootHeader" class="container_12">
			<div class="qq" id="dvTab" style="top:0px;">
				<ul id="rootTopMenus" class="qd nui-tabs">
					<li id="indexli" href="javascript:void(0)"
						onclick="loadModuleMenus('',this)" class="qa nui-tabs-item""><span
						class="nui-tabs-item-text">首页</span>
					</li>
					<c:forEach items="${root}" var="menu">
						<li href="javascript:void(0)"
							onclick="loadModuleMenus('${menu.id}',this)"
							class="qa nui-tabs-item"><span class="nui-tabs-item-text">${menu.name}
						</span>
						</li>
					</c:forEach>
				</ul>
				<div class="pv"></div>
			</div>
		</header>
		<section class="frame-main" style="top:35px;">

			<div id="dvFrameMainNav" class="frame-main-nav">
				<div onclick="switchMenu(this)" data-t="1" id="switchMenuBtn"
					style="position: absolute;right: .5em;top: 1em;margin-top: -8px;background: url(img/icon_jd.png) no-repeat -22px -15px;cursor: pointer;width: 16px;height: 16px;padding: 0;"></div>
				<aside aria-labeledby="dvNavTitle" role="navigation">
					<div class="pj nui-scroll" id="navtree">
						<ul class="collapsible accordion nui-tree" role="tree"></ul>
					</div>
				</aside>
			</div>
			<section id="mainContent"
				class="frame-main-cont frame-main-cont-first" role="main">
				<div id="dvContainer" style="overflow:visible;"></div>
			</section>
		</section>
	</c:otherwise>
</c:choose>

<script type="text/javascript">
	$(function() {
		if (navigator.userAgent.match(/mobile/i)) {
			$("#dvContainer").css({
				"-webkit-overflow-scrolling" : "touch",
				"overflow" : "auto"
			});
		}
	});
</script>
<div id="toastMessage" class="toast-msg"></div>

<c:choose>
	<c:when test="${empty noHeader }">
		<footer class="skin" id="skin">
			<div class="skin-item skin-top"></div>
			<div class="skin-item skin-top-left"></div>
			<div class="skin-item skin-top-right"></div>
			<div class="skin-item skin-left"></div>
			<div class="skin-item skin-left-top"></div>
			<div class="skin-item skin-right"></div>
			<div class="skin-item skin-right-hack"></div>
			<div class="skin-item skin-bottom"></div>
			<div class="skin-item skin-bottom-left"></div>
			<div class="skin-item skin-bottom-right"></div>
			<div class="skin-item skin-fullScreen" id="skinFullScreen"></div>
		</footer>
	</c:when>
	<c:otherwise>
		<footer class="skin" id="skin">
			<div class="skin-item skin-top" style="height:0px;"></div>
			<div class="skin-item skin-top-left"></div>
			<div class="skin-item skin-top-right" style="background-image:none">
			</div>
			<div class="skin-item skin-left"></div>
			<div class="skin-item skin-left-top"></div>
			<div class="skin-item skin-right"></div>
			<div class="skin-item skin-right-hack"></div>
			<div class="skin-item skin-bottom"></div>
			<div class="skin-item skin-bottom-left"></div>
			<div class="skin-item skin-bottom-right"></div>
			<div class="skin-item skin-fullScreen" id="skinFullScreen"></div>
		</footer>
	</c:otherwise>
</c:choose>



<%
  CcAgentService ccAgentService = ContextHolder
      .getSpringBean("ccAgentService");

  JqGridRequest req = new JqGridRequest();
  req.addFilterRule("username", JqGridFilterRuleOp.eq,
      ContextHolder.getLoginUsername());
  CcAgent cag = ccAgentService.findOneByRequest(req);

  if (cag != null) {
%>
<jsp:include page="callcenter/toolbar.jsp"></jsp:include>
<%
  }
%>
<jsp:include page="includes/bottom.jsp"></jsp:include>